/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package moduleView.impl;

import java.util.Collection;
import java.util.Map;

import moduleView.DependecyModule;
import moduleView.Diagram;
import moduleView.Feature;
import moduleView.Module;
import moduleView.ModuleInterface;
import moduleView.ModuleViewPackage;
import moduleView.Scenario;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Diagram</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link moduleView.impl.DiagramImpl#getName <em>Name</em>}</li>
 *   <li>{@link moduleView.impl.DiagramImpl#getIncludeScenario <em>Include Scenario</em>}</li>
 *   <li>{@link moduleView.impl.DiagramImpl#getIncludeFeature <em>Include Feature</em>}</li>
 *   <li>{@link moduleView.impl.DiagramImpl#getIncludeModule <em>Include Module</em>}</li>
 *   <li>{@link moduleView.impl.DiagramImpl#getIncludeInterface <em>Include Interface</em>}</li>
 *   <li>{@link moduleView.impl.DiagramImpl#getIncludeRelationDM <em>Include Relation DM</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DiagramImpl extends EObjectImpl implements Diagram {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = "";

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getIncludeScenario() <em>Include Scenario</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIncludeScenario()
	 * @generated
	 * @ordered
	 */
	protected EList<Scenario> includeScenario;

	/**
	 * The cached value of the '{@link #getIncludeFeature() <em>Include Feature</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIncludeFeature()
	 * @generated
	 * @ordered
	 */
	protected EList<Feature> includeFeature;

	/**
	 * The cached value of the '{@link #getIncludeModule() <em>Include Module</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIncludeModule()
	 * @generated
	 * @ordered
	 */
	protected EList<Module> includeModule;

	/**
	 * The cached value of the '{@link #getIncludeInterface() <em>Include Interface</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIncludeInterface()
	 * @generated
	 * @ordered
	 */
	protected EList<ModuleInterface> includeInterface;

	/**
	 * The cached value of the '{@link #getIncludeRelationDM() <em>Include Relation DM</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIncludeRelationDM()
	 * @generated
	 * @ordered
	 */
	protected EList<DependecyModule> includeRelationDM;
	
	protected static DiagramImpl diagrama = null;
	
	public static DiagramImpl getInstanceDiagram() {
		if (diagrama == null) {
			diagrama = new DiagramImpl();
		}
		return diagrama;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DiagramImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ModuleViewPackage.Literals.DIAGRAM;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModuleViewPackage.DIAGRAM__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Scenario> getIncludeScenario() {
		if (includeScenario == null) {
			includeScenario = new EObjectContainmentEList<Scenario>(Scenario.class, this, ModuleViewPackage.DIAGRAM__INCLUDE_SCENARIO);
		}
		return includeScenario;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Feature> getIncludeFeature() {
		if (includeFeature == null) {
			includeFeature = new EObjectContainmentEList<Feature>(Feature.class, this, ModuleViewPackage.DIAGRAM__INCLUDE_FEATURE);
		}
		return includeFeature;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Module> getIncludeModule() {
		if (includeModule == null) {
			includeModule = new EObjectContainmentEList<Module>(Module.class, this, ModuleViewPackage.DIAGRAM__INCLUDE_MODULE);
		}
		return includeModule;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ModuleInterface> getIncludeInterface() {
		if (includeInterface == null) {
			includeInterface = new EObjectContainmentEList<ModuleInterface>(ModuleInterface.class, this, ModuleViewPackage.DIAGRAM__INCLUDE_INTERFACE);
		}
		return includeInterface;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DependecyModule> getIncludeRelationDM() {
		if (includeRelationDM == null) {
			includeRelationDM = new EObjectContainmentEList<DependecyModule>(DependecyModule.class, this, ModuleViewPackage.DIAGRAM__INCLUDE_RELATION_DM);
		}
		return includeRelationDM;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public boolean validate(DiagnosticChain diagnostic, Map<Object, Object> context) {
		boolean valid = true;
		/*if (diagnostic != null) {
			// 01: Validacion de Escenarios
			valid &= validateScenaries(diagnostic, context);
			// 02: Validacion de Features
			valid &= validateFeatures(diagnostic, context);
			// 03: Validacion de Modulos
			valid &= validateModules(diagnostic, context);
			// 04: Validacion de Interfaces de Modulos
			valid &= validateModuleInterfaces(diagnostic, context);
		}*/
		return valid;
	}

	/**
	 *
	 * @param diagnostic
	 * @param context
	 * @return
	 */
	/*private boolean validateScenaries(DiagnosticChain diagnostic, Map<Object, Object> context) {
		boolean eval = false;
		// Pido todos los escenarios que hay en el diagrama.
		Iterator<Scenario> iteratorEscenario = this.getIncludeScenario().iterator();
		while (iteratorEscenario.hasNext()) {
			Scenario vEscenario = iteratorEscenario.next();
			eval &= vEscenario.validateHasFeature(diagnostic, context);
			eval &= vEscenario.validateHasModule(diagnostic, context);
		}
		return eval;
	}*/

	/**
	 *
	 * @param diagnostic
	 * @param context
	 * @return
	 */
	/*private boolean validateFeatures(DiagnosticChain diagnostic, Map<Object, Object> context) {
		boolean eval = false;
		// Pido todos los features que hay en el diagrama.
		Iterator<Feature> iteratorFeatures = this.getIncludeFeature().iterator();
		while (iteratorFeatures.hasNext()) {
			Feature vFeature = iteratorFeatures.next();
			eval &= vFeature.validateFAHasFeature(diagnostic, context);
			eval &= vFeature.validateFAHasModule(diagnostic, context);
			eval &= vFeature.validateFCHasFeature(diagnostic, context);
			eval &= vFeature.validateHasModule(diagnostic, context);
		}
		return eval;
	}*/

	/**
	 *
	 * @param diagnostic
	 * @param context
	 * @return
	 */
	/*private boolean validateModules(DiagnosticChain diagnostic, Map<Object, Object> context) {
		boolean eval = false;
		// Pido todos los modulos que hay en el diagrama.
		Iterator<Module> iteratorModules = this.getIncludeModule().iterator();
		while (iteratorModules.hasNext()) {
			Module vModule = iteratorModules.next();
			eval &= vModule.validateImplementsInterface(diagnostic, context);
			eval &= vModule.validateIncludeResponsability(diagnostic, context);
			eval &= vModule.validateContainerFC(diagnostic, context);
		}
		return eval;
	}*/

	/**
	 *
	 * @param diagnostic
	 * @param context
	 * @return
	 */
	/*private boolean validateModuleInterfaces(DiagnosticChain diagnostic, Map<Object, Object> context) {
		boolean eval = false;
		// Pido todas las interfaces de modulos que hay en el diagrama.
		Iterator<ModuleInterface> iteratorInterfaces = this.getIncludeInterface().iterator();
		while (iteratorInterfaces.hasNext()) {
			ModuleInterface vModuleInterface = iteratorInterfaces.next();
			eval &= vModuleInterface.validateHasOperation(diagnostic, context);
			eval &= vModuleInterface.validateLinkUses(diagnostic, context);
			eval &= vModuleInterface.validateIsImplemented(diagnostic, context);
			
		}
		return eval;
	}*/

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ModuleViewPackage.DIAGRAM__INCLUDE_SCENARIO:
				return ((InternalEList<?>)getIncludeScenario()).basicRemove(otherEnd, msgs);
			case ModuleViewPackage.DIAGRAM__INCLUDE_FEATURE:
				return ((InternalEList<?>)getIncludeFeature()).basicRemove(otherEnd, msgs);
			case ModuleViewPackage.DIAGRAM__INCLUDE_MODULE:
				return ((InternalEList<?>)getIncludeModule()).basicRemove(otherEnd, msgs);
			case ModuleViewPackage.DIAGRAM__INCLUDE_INTERFACE:
				return ((InternalEList<?>)getIncludeInterface()).basicRemove(otherEnd, msgs);
			case ModuleViewPackage.DIAGRAM__INCLUDE_RELATION_DM:
				return ((InternalEList<?>)getIncludeRelationDM()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ModuleViewPackage.DIAGRAM__NAME:
				return getName();
			case ModuleViewPackage.DIAGRAM__INCLUDE_SCENARIO:
				return getIncludeScenario();
			case ModuleViewPackage.DIAGRAM__INCLUDE_FEATURE:
				return getIncludeFeature();
			case ModuleViewPackage.DIAGRAM__INCLUDE_MODULE:
				return getIncludeModule();
			case ModuleViewPackage.DIAGRAM__INCLUDE_INTERFACE:
				return getIncludeInterface();
			case ModuleViewPackage.DIAGRAM__INCLUDE_RELATION_DM:
				return getIncludeRelationDM();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ModuleViewPackage.DIAGRAM__NAME:
				setName((String)newValue);
				return;
			case ModuleViewPackage.DIAGRAM__INCLUDE_SCENARIO:
				getIncludeScenario().clear();
				getIncludeScenario().addAll((Collection<? extends Scenario>)newValue);
				return;
			case ModuleViewPackage.DIAGRAM__INCLUDE_FEATURE:
				getIncludeFeature().clear();
				getIncludeFeature().addAll((Collection<? extends Feature>)newValue);
				return;
			case ModuleViewPackage.DIAGRAM__INCLUDE_MODULE:
				getIncludeModule().clear();
				getIncludeModule().addAll((Collection<? extends Module>)newValue);
				return;
			case ModuleViewPackage.DIAGRAM__INCLUDE_INTERFACE:
				getIncludeInterface().clear();
				getIncludeInterface().addAll((Collection<? extends ModuleInterface>)newValue);
				return;
			case ModuleViewPackage.DIAGRAM__INCLUDE_RELATION_DM:
				getIncludeRelationDM().clear();
				getIncludeRelationDM().addAll((Collection<? extends DependecyModule>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ModuleViewPackage.DIAGRAM__NAME:
				setName(NAME_EDEFAULT);
				return;
			case ModuleViewPackage.DIAGRAM__INCLUDE_SCENARIO:
				getIncludeScenario().clear();
				return;
			case ModuleViewPackage.DIAGRAM__INCLUDE_FEATURE:
				getIncludeFeature().clear();
				return;
			case ModuleViewPackage.DIAGRAM__INCLUDE_MODULE:
				getIncludeModule().clear();
				return;
			case ModuleViewPackage.DIAGRAM__INCLUDE_INTERFACE:
				getIncludeInterface().clear();
				return;
			case ModuleViewPackage.DIAGRAM__INCLUDE_RELATION_DM:
				getIncludeRelationDM().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ModuleViewPackage.DIAGRAM__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case ModuleViewPackage.DIAGRAM__INCLUDE_SCENARIO:
				return includeScenario != null && !includeScenario.isEmpty();
			case ModuleViewPackage.DIAGRAM__INCLUDE_FEATURE:
				return includeFeature != null && !includeFeature.isEmpty();
			case ModuleViewPackage.DIAGRAM__INCLUDE_MODULE:
				return includeModule != null && !includeModule.isEmpty();
			case ModuleViewPackage.DIAGRAM__INCLUDE_INTERFACE:
				return includeInterface != null && !includeInterface.isEmpty();
			case ModuleViewPackage.DIAGRAM__INCLUDE_RELATION_DM:
				return includeRelationDM != null && !includeRelationDM.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //DiagramImpl
